/***********************************************************************
** Copyright (C) 2011 Anthony Naddeo <anthony.naddeo@gmail.com>
**
** This file is part of qtweather-qml
**
** qtweather-qml is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 3 of the License, or
** (at your option) any later version.
**
** qtweather-qml is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this package; If not, see <http://www.gnu.org/licenses/>.
**
***********************************************************************/

import QtQuick 1.1
import com.meego 1.0


PageStackWindow {
    id: appWindow
    initialPage: mainPage
	showStatusBar: mainPage.width > mainPage.height ? false : true
	Component.onCompleted: {
		timer.running = true
		theme.inverted = true
	}

	Timer{id: timer
		interval: 250
		onTriggered: {
			loader.sourceComponent = settingsComp
			if(!Utilities.defaultHome() || Utilities.home(Utilities.defaultHome()) === "" ){
				loader.item.open()
			}else
				mainPage.zipcode = Utilities.home(Utilities.defaultHome())
		}
	}

	//pages
	MainPage{id: mainPage}
	Loader{id: loader}

	Component{
		id: settingsComp
		Settings{
			visualParent: pageStack
			onSelected: mainPage.zipcode = zipcode
			Connections{
				target: mainPage
				onFinished: update(zipcode)
			}
		}
	}




	ToolBarLayout {
        id: commonTools
        visible: true

		ToolIcon { id: menu; platformIconId: "toolbar-view-menu";
			anchors.right: parent===undefined ? undefined : parent.right
//			onClicked: (myMenu.status == DialogStatus.Closed) ? myMenu.open() : myMenu.close()
			onClicked: loader.item.status === DialogStatus.Closed ? loader.item.open() : loader.item.close()

		}
		ToolIcon { platformIconId: "toolbar-back";
			anchors.left: parent===undefined ? undefined : parent.left
			onClicked: appWindow.pageStack.pop()
			visible: appWindow.pageStack.depth > 1 ? true : false
		}
		BusyIndicator{
			anchors.left: parent.left
			anchors.leftMargin: 10
			running: mainPage.busy
			visible: running
		}

		Item {
			id: hazardItem
			anchors.fill: parent
			anchors.rightMargin: menu.width
			clip: true

			Label{
				id: label
				text: mainPage.hazards
				anchors.verticalCenter: parent.verticalCenter
				anchors.left: parent.right
				font.pixelSize: 30
				visible: !mainPage.busy
				font.family: "URW Gothic L"

//				PropertyAnimation{
//					target: label
//					property: "anchors"
////					from: hazardItem.width
//					to: {right: hazardItem.left; left: undefined}
//					loops: Animation.Infinite
//					duration: 10000
//					running: Qt.application.active
//				}
			}

		}


		Label{
			text: mainPage.title
			anchors.left: parent.left
			anchors.verticalCenter: parent.verticalCenter
			font.pixelSize: 35
			visible: !mainPage.busy
			font.family: "URW Gothic L"
		}
    }





	Menu {
		id: myMenu
		visualParent: pageStack
		MenuLayout {
			MenuItem { text: "Settings"; onClicked:loader.item.open() }
		}
	}
}
